package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 上传素材
 */
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * TODO
     *      - 上传素材图片
     *      - uri: /api/v1/material/upload_picture
     *      - method: post
     * @param file  MultipartFile
     * @return      ResponseResult
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam("multipartFile") MultipartFile file) {
        return wmMaterialService.uploadPicture(file);
    }

    /**
     * TODO
     *      - 分页显示素材列表
     *      - uri: /api/v1/material/list
     *      - method: post
     * @param wmMaterialDto  WmMaterialDto
     * @return      ResponseResult
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmMaterialDto wmMaterialDto) {
        return wmMaterialService.findAll(wmMaterialDto);
    }

    /**
     * TODO
     *      - 收藏素材
     *      - uri: /api/v1/material/collect/{id}
     *      - params: id
     *      - method: get
     * @return      ResponseResult
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id) {
        return wmMaterialService.changeCollect(id, (short) 1);
    }

    /**
     * TODO
     *      - 取消收藏素材
     *      - uri: /api/v1/material/cancel_collect/{id}
     *      - params: id
     *      - method: get
     * @return      ResponseResult
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id) {
        return wmMaterialService.changeCollect(id, (short) 0);
    }

    /**
     * TODO
     *      - 删除素材
     *      - uri: /api/v1/material/del_picture/{id}
     *      - params: id
     *      - method: get
     * @return      ResponseResult
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer id) {
        return wmMaterialService.delPicture(id);
    }
}
